﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using UniversityStudentManagemnetSystem.BLL;
using UniversityStudentManagemnetSystem.DAO.DAL;

namespace UniversityStudentManagemnetSystem.UI
{
    public partial class PersonalStudentInformation : System.Web.UI.Page
    {
        Student aStudent=new Student();
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                PopulatedNotEnableTextBoxes();
            }
        }

        private void PopulatedNotEnableTextBoxes()
        {
            nameLabel.Visible = false;
            regNoLabel.Visible = false;
            contactNoLabel.Visible = false;
            departmentLabel.Visible = false;
            addressLabel.Visible = false;
            registrationDateLabel.Visible = false;
            emailLabel.Visible = false;

            nameTextBox.Visible = false;
            regNoTextBox.Visible = false;
            contactNoTextBox.Visible = false;
            departmentTextBox.Visible = false;
            addressTextBox.Visible = false;
            registationDateTextBox.Visible = false;
            emaiTextBox.Visible = false;

        }

        protected void searchButton_Click(object sender, EventArgs e)
        {
            try
            {
                string regNoOrEmailOrContactNo = regNoOrEmailTextBox.Text;
                StudentManager manager = new StudentManager();
                aStudent = manager.GetStudentForRegNoOrEmail(regNoOrEmailOrContactNo);
                VisibleTextBoxesAndLabels();
                nameTextBox.Text = aStudent.Name;
                regNoTextBox.Text = aStudent.RegNo;
                emaiTextBox.Text = aStudent.Email;
                contactNoTextBox.Text = aStudent.ContactNumber;
                departmentTextBox.Text = aStudent.Department.Code;
                addressTextBox.Text = aStudent.Address;
                registationDateTextBox.Text = aStudent.RegistrationDate.ToString();
            }
            catch(FormatException exception)
                {
                    messageLabel.ForeColor = Color.Red;
                    messageLabel.Text = exception.Message;
             }
            catch (Exception exception)
            {
                messageLabel.ForeColor = Color.Red;
                messageLabel.Text = exception.Message;
            }
           
            
        }

        private void VisibleTextBoxesAndLabels()
        {
            nameLabel.Visible = true;
            regNoLabel.Visible = true;
            contactNoLabel.Visible = true;
            departmentLabel.Visible = true;
            addressLabel.Visible = true;
            registrationDateLabel.Visible = true;
            emailLabel.Visible = true;

            nameTextBox.Visible = true;
            regNoTextBox.Visible = true;
            contactNoTextBox.Visible = true;
            departmentTextBox.Visible = true;
            addressTextBox.Visible = true;
            registationDateTextBox.Visible = true;
            emaiTextBox.Visible = true;
        }
    }
}